<template>
  <!-- 列表 -->
  <ContentWrap>
    
    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="参与人" align="center" prop="userName" />
      <el-table-column label="参与部门" align="center" prop="deptName" />
      <el-table-column label="参与次数" align="center" prop="attendCount" />
      <el-table-column label="综合评分" align="center" prop="avgScore" />
      <el-table-column
        label="最近上传时间"
        align="center"
        prop="lastUpdateTime"
        :formatter="dateFormatter"
        width="180px"
      />
      <el-table-column label="操作" align="center">
        <template #default="scope"> 
          
          <router-link :to="'/activity/record/' + scope.row.activityId +'/' + scope.row.userId">
            <el-button link type="primary">查看详情</el-button>
          </router-link>
          
        </template>
      </el-table-column>
    </el-table>
   
  </ContentWrap>
</template>
<script setup lang="ts">
import { dateFormatter } from '@/utils/formatTime'
import { ActivityApi } from '@/api/school/activity'

const props = defineProps<{
  activityId?: number // 活动ID（主表的关联字段）
}>()
const loading = ref(false) // 列表的加载中
const list = ref([]) // 列表的数据
const queryParams = reactive({
  pageNo: 1,
  pageSize: 10,
  activityId: undefined as unknown
})



/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await ActivityApi.getActivityRecordOverview(queryParams)
    list.value = data
  } finally {
    loading.value = false
  }
}

/** 监听主表的关联字段的变化，加载对应的子表数据 */
watch(
  () => props.activityId,
  (val: number) => {
    if (!val) {
      return
    }
    queryParams.activityId = val
    getList()
  },
    { immediate: true, deep: true }
)

</script>